What is camelcase?
The camelcase npm package is used to convert strings to camel case. This means it takes input strings with spaces, hyphens, underscores, or a mix of different delimiters and converts them into a string where the first letter of each word is capitalized except for the first word, and all the words are joined without spaces.
What are camelcase's main functionalities?
String Conversion to Camel Case
Converts a hyphenated string to camel case.
"foo-bar".pipe(camelCase); // 'fooBar'
Handling Multiple Delimiters
Converts a string with multiple delimiters to camel case.
"foo_bar--baz foo".pipe(camelCase); // 'fooBarBazFoo'
Preserving Consecutive Uppercase Characters
Converts a string to camel case while preserving consecutive uppercase characters.
"foo-BAR".pipe(camelCase({ pascalCase: false })); // 'fooBAR'
Converting to Pascal Case
Converts a string to pascal case, which is similar to camel case but with the first letter capitalized.
"foo-bar".pipe(camelCase({ pascalCase: true })); // 'FooBar'
Other packages similar to camelcase
change-case
A package that provides various case conversion utilities including camel case, snake case, pascal case, and more. It offers more comprehensive case conversion options compared to camelcase.
to-camel-case
A package that converts a string to camel case. It is similar to camelcase but is a smaller package with fewer features and customization options.
param-case
This package is designed to convert strings to param case (kebab case). While it serves a different purpose, it is related in the sense that it deals with string case conversion, just like camelcase.
camelcase ![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)
Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: foo-bar
→ fooBar
Install
$ npm install camelcase
Usage
const camelCase = require('camelcase');
camelCase('foo-bar');
camelCase('foo_bar');
camelCase('Foo-Bar');
camelCase('Foo-Bar', {pascalCase: true});
camelCase('--foo.bar', {pascalCase: false});
camelCase('foo bar');
console.log(process.argv[3]);
camelCase(process.argv[3]);
camelCase(['foo', 'bar']);
camelCase(['__foo__', '--bar'], {pascalCase: true});
API
camelCase(input, [options])
input
Type: string
string[]
String to convert to camel case.
options
Type: Object
pascalCase
Type: boolean
Default: false
Uppercase the first character: foo-bar
→ FooBar
Security
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
Related
- decamelize - The inverse of this module
- uppercamelcase - Like this module, but to PascalCase instead of camelCase
- titleize - Capitalize every word in string
- humanize-string - Convert a camelized/dasherized/underscored string into a humanized one
License
MIT © Sindre Sorhus